exports.addingServicedRecords = (req, res) => {

    var bodyParams = req.routeInfo.bodyParams;

    var resultData = {};

    console.log(bodyParams);

    var c_id = 0;

    function searchCustomer(cb) {
        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.artCustomerSearch.Request_Api_Url + "/c_is_delete/0/c_openid/" + bodyParams.apurr_openid,
                method: 'POST',
                data: {
                    fields: ['c_id',].join(",")
                }
            },
            function (data) {

                if (data.result.data.length > 0) {
                    c_id = data.result.data[0].c_id
                }

                cb()

            }
        )
    }

    function createNewCustomer(cb) {

        if (parseInt(c_id) > 0) {
            cb()
        } else {

            var addParam = {
                c_phone: bodyParams.apo_phone,
                c_uid: bodyParams.cs_uid,
                c_name: bodyParams.apo_nickname,
                c_weixin_nickname: bodyParams.apo_nickname,
                c_openid: bodyParams.apo_openid,
                c_is_buy: 1,
                c_osid: bodyParams.c_osid,
                c_distribution_status: 1,
                c_create_time: Date.parse(new Date()) / 1000,
            };
            R.SEND_HTTP(
                req,
                res,
                {
                    url: CORE_APIConfig.coreAPI.artCustomerAdd.Request_Api_Url,
                    method: 'POST',
                    data: addParam
                },
                function (data) {

                    c_id = data.result;
                    cb();

                }
            )
        }
    }

    //添加跟进记录
    function AddRecords(cb) {

        var addParam = {
            cs_cid: c_id,
            cs_uid: bodyParams.cs_uid,
            cs_content: bodyParams.cs_content,
            cs_way: bodyParams.cs_way,
            cs_create_time: Date.parse(new Date()) / 1000,
        };

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.artCustomerServiceAdd.Request_Api_Url,
                method: 'POST',
                data: addParam
            },
            function (data) {

                resultData.addResult = data.result;
                cb();

            }
        )
    }

    //客户服务状态更新
    function customerServiceStatusUpdate(cb) {

        var updateParam = {
            update_where: 'c_id',
            c_id: c_id,
            c_service_status: 1,
        };

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.artCustomerUpdate.Request_Api_Url,
                method: 'POST',
                data: updateParam
            },
            function (data) {

                resultData.updateResult = data.success;
                cb();

            }
        )
    }

    //客户订单服务状态更新
    function customerOrderServiceStatusUpdate(cb) {
        R.SEND_HTTP(
            req,
            res,
            {
                url: config.external_server.apiAddress + "/organization/update_art_product_order",
                method: 'POST',
                data: {
                    apo_no: bodyParams.apo_no,
                    apo_service_status: 1,
                }
            },
            function (data) {

                resultData.updateOrderServiceResult = data.success;

                cb();

            }
        )
    }


    F.Serial([
        searchCustomer,
        createNewCustomer,
        searchCustomer,
        AddRecords,
        customerServiceStatusUpdate,
        customerOrderServiceStatusUpdate,
    ], () => {
        RES.successResponse(res, resultData);
    })


}